// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Weapon/TUBaseWeapon.h"
#include "TURifleWeapon.generated.h"

class UTUWeaponFXComponent;
class UNiagaraComponent;

UCLASS()
class THEMUP_API ATURifleWeapon : public ATUBaseWeapon
{
	GENERATED_BODY()
	
public:
	ATURifleWeapon();

	virtual void StartFire() override;
	virtual void StopFire() override;

protected:
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon")
	float TimeBetweenShots = 0.1f;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon")
	float BulletSpread = 1.5f;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon")
	float DamageAmount = 50.0f;
	UPROPERTY(VisibleAnywhere, Category = "VFX")
	UTUWeaponFXComponent* WeaponFXComponent;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "VFX")
	UNiagaraSystem* TraceFX;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "VFX")
	FString TraceTargetName = "TraceTarget";


	virtual void BeginPlay() override;
	virtual void MakeShot() override;
	void MakeDamage(const FHitResult& HitResult);
	virtual bool GetTraceData(FVector& TraceStart, FVector& TraceEnd) const override;
	void SetFXActive(bool IsActive);
	void InitFX();
	void SpawnTraceFX(const FVector& TraceStart, const FVector& TraceEnd);


private:
	AController* GetController() const;
	UPROPERTY()
	UNiagaraComponent* MuzzleFXComponent;
	
	FTimerHandle ShotTimerHandle;
};
